<template>

  <a-table :columns="columns"
           :data-source="Studentdata"
           :pagination="pagination"
           @showSizeChange="onShowSizeChanger"
           @change="onChange"
  >
    <a slot="name" slot-scope="text">{{ text }}</a>
    <span slot="customTitle">姓名</span>
    <span slot="tags" slot-scope="tags">
    </span>
    <span slot="action" slot-scope="text, record">
      <a @click="editClick(record.key,record)">编辑</a>
      <a-divider type="vertical"/>
      <a-popconfirm
        title="是否删除"
        ok-text="确认"
        cancel-text="取消"
        @confirm="confirm(record.key)"
        @cancel="cancel"

      >
      <a>删除</a>
      </a-popconfirm>
      <a-divider type="vertical"/>
      <a class="ant-dropdown-link"> 更多操作 <a-icon type="down"/> </a>
    </span>
  </a-table>
</template>
<script>


  const columns = [
    {
      dataIndex: 'name',
      key: 'name',
      slots: {title: 'customTitle'},
      scopedSlots: {customRender: 'name'},
    },
    {
      title: '学号',
      dataIndex: 'id',
      key: 'id',
    },
    {
      title: '班级',
      dataIndex: 'className',
      key: 'className',
    },
    {
      title: '性别',
      key: 'sex',
      dataIndex: 'sex',
    },
    {
      title: '操作',
      key: 'action',
      scopedSlots: {customRender: 'action'},
    },
  ];


  export default {
    data() {
      return {
        columns,
        studentDataTotal:[],
        // studentItem:{},
        pagination: {
          // 自己的分页
          showQuickJumper: true,
          showSizeChanger: true,
          pageSizeOptions: ['10', '20', '30', '40', '50'],
          current: 1,
          pageSize: 10,
          total: this.Studentdata.length,
          showTotal: (total, range) => `当前${range[0]}-${range[1]}  共${total}条记录 `
        },
      };
    },
    props: {
      Studentdata: {
        type: Array,
        default() {
          return []
        }
      }
    },


    methods: {
      editClick(key, record) {
        this.$store.commit('changeVisibe2')
        this.$bus.$emit('editStudent', key, record)
        this.$emit('editStudent2', key, record)
      },
      confirm(key) {
        this.$emit('studentDelete', key)
        this.$message.success('删除成功');
      },
      cancel() {
        this.$message.error('已取消');
      },
      onShowSizeChanger(current, pageSize) {
        this.current = current;
        this.pageSize = pageSize;
      },
      onChange(pageNumber) {
        this.pagination.current = pageNumber.current;
      },
    },

  };
</script>